<?php
declare(strict_types=1);

namespace App\Controller;

use App\Service\BlocksService;
use App\Service\PlayletService;
use Hyperf\DbConnection\Db;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\ResponseInterface;

class BlocksController extends BaseController
{
    #[Inject]
    private BlocksService $blocksService;

    #[Inject]
    private PlayletService $playletService;

    // 榜单列表
    public function list($applet_id)
    {
        $applet_id = str_replace(".json","",$applet_id);
        $applet_id = (int)$applet_id;
        $redata = $this->blocksService->get_blocks_list($applet_id);
        return $this->resultResponse(["data"=>$redata]);
    }

//    public function ranking($blocks_id)
    public function ranking($blocks_id,RequestInterface $request,ResponseInterface $response)
    {
        # 榜单列表
//        $blocks_id = str_replace(".json","",$blocks_id);
        $blocks_id = (int)$blocks_id;
        $xc_open_id = $request->input("xc_open_id","");
        $applet_id = $this->get_applet_id();
        $playlet_id = $this->playletService->get_playlet_id($applet_id,$xc_open_id);
        $redata = $this->blocksService->get_ranking_list($blocks_id,$playlet_id);
        return $this->resultResponse(["data"=>$redata]);
    }

    public function user_icons($applet_id){
        #我的静态
        $applet_id = str_replace(".json","",$applet_id);
        $applet_id = (int)$applet_id;
        $redata = $this->blocksService->user_icons_list($applet_id);
        return $this->resultResponse(["data"=>$redata]);
    }
    public function customer($applet_id){
        $url = 'https://ky-dj.oss-accelerate.aliyuncs.com/101698926679_.pic.jpg';
        #我的静态
        return $this->resultResponse(["data"=>$url]);
    }

    public function news_info($news_id){
        echo "news_info".PHP_EOL;
        print_r($news_id);
        $news_id = str_replace(".json","",$news_id);
        $news_id = (int)$news_id;
        $redata = $this->blocksService->news_info($news_id);
        return $this->resultResponse(["data"=>$redata]);
    }

    public function wallpaper_list($applet_id,$template_type){
        $applet_id = str_replace(".json","",$applet_id);
        $applet_id = (int)$applet_id;
        $template_type = str_replace(".json","",$template_type);
        $template_type = (int)$template_type;
        $redata = $this->blocksService->wallpaper_list($applet_id,$template_type);
        return $this->resultResponse(["data"=>$redata]);
    }

    public function hot_broadcast($applet_id){
        # 热播排行
        $applet_id = str_replace(".json","",$applet_id);
        $applet_id = (int)$applet_id;
        $redata = $this->blocksService->get_recommend($applet_id,2);
        return $this->resultResponse(["data"=>$redata]);
    }

    public function sys_time(){
        $redata["sys_time"] = time();
        return $this->resultResponse(["data"=>$redata]);
    }

    public function sys_share_config($applet_id){
        # 分享系统配置
        $applet_id = str_replace(".json","",$applet_id);
        $applet_id = (int)$applet_id;
        $data = $this->blocksService->share_config($applet_id);
        return $this->resultResponse(["data"=>$data]);
    }
}